package me.firstapp.bts.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import me.firstapp.bts.service.StatisticsJobService;
import me.firstapp.common.json.ListObject;
import me.firstapp.common.module.system.JsonApiClient;
import me.firstapp.spi.system.ApiClientService;
import me.firstapp.spi.system.StatisticsService;

@Service
public class StatisticsJobServiceImpl implements StatisticsJobService {

	private static Logger logger = LoggerFactory.getLogger(StatisticsJobService.class);

	@Autowired
	private ApiClientService apiClientService;

	@Autowired
	private StatisticsService statisticsService;

	@Override
	public void executeStatistics() {
		long start = System.currentTimeMillis();
		logger.info("............开始批处理统计...........");
		ListObject<JsonApiClient> clientsJson = apiClientService.findAll();
		if (clientsJson != null) {
			List<JsonApiClient> clients = clientsJson.getItems();
			if (clients != null && !clients.isEmpty()) {
				for (JsonApiClient client : clients) {
					statisticsService.executeStatistics(client.getId());
				}
			}
		}
		logger.info("............结束批处理统计...........耗时===》" + (System.currentTimeMillis() - start));
	}

}
